package com.crl.game.simulation.server.state
{
	import com.crl.game.simulation.server.decoder.IServerRouter;
	import com.crl.game.simulation.common.state.ControlState;
	import com.crl.net.SocketDelegate;
	import com.crl.net.transfer.Command;

	
	/**
	 * 用户控制; 
	 * @author crl
	 * 
	 */	
	public class UserControlState extends ControlState
	{
		protected var receiveCommandQueue:Vector.<Command>;
		protected var sendCommandQueue:Vector.<Command>;
		
		private var socket:SocketDelegate;
		private var router:IServerRouter;
		public function UserControlState(socketDelegate:SocketDelegate,router:IServerRouter)
		{
			super();
			this.router=router;
			this.socket=socketDelegate;
			this.socket.onData=onData;
			
			receiveCommandQueue=new Vector.<Command>();
			sendCommandQueue=new Vector.<Command>();
		}
		
		/**
		 * 当接收到socket消息时; 
		 * @param code
		 * @param data
		 * 
		 */		
		private function onData(code:int,data:*):void{
			var command:Command=new Command();
			command.code=code;
			command.data=data;
			
			router.route(command,null);
		}
		
		override public function sendCommand(command:Command):void{
			socket.send(command.code,command.data);
		}
		
		override public function receiveCommand(command:Command):void{
			//queueReceiveCommand(command);
		}
		
	}
}